package com.swxc.smartorder.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.swxc.smartorder.R;
import com.swxc.smartorder.entity.OrderBean;
import com.swxc.smartorder.utils.DateUtil;

import java.util.List;

/**
 * Author   Administrator
 * Date     2018/3/29
 * Desc     eg
 *
 * @author Administrator
 */
public class AdapterWork extends BaseQuickAdapter<OrderBean, BaseViewHolder> {


    public AdapterWork(@Nullable List<OrderBean> data) {
        super(R.layout.item_work, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, OrderBean item) {


        ImageView mIvComplete = helper.getView(R.id.iv_compete_flag);
        TextView mTvStatus = helper.getView(R.id.tv_stature);
        TextView mTvFlag = helper.getView(R.id.tv_flag);
        TextView mTvTitle = helper.getView(R.id.tv_title);
        TextView mTvDate = helper.getView(R.id.tv_date);
        mTvTitle.setText(item.getTitle());
        mTvDate.setText(DateUtil.INSTANCE.getTimeFormatString(item.getCreateTime()));

        if (item.getTimeout()) {
            mIvComplete.setVisibility(View.INVISIBLE);
            mTvStatus.setText("超时工单");
            mTvStatus.setTextColor(Color.parseColor("#fb5f5f"));
            mTvFlag.setVisibility(View.VISIBLE);
            mTvFlag.setBackgroundColor(Color.parseColor("#fb5f5f"));
        } else {
            switch (item.getStatus()) {
                case "ACCEPTED":
                    mIvComplete.setVisibility(View.INVISIBLE);
                    mTvFlag.setVisibility(View.INVISIBLE);
                    setFlagColor(item.getPriorityLevel(), mTvStatus);
                    break;
                case "UNTREATED":
                    mIvComplete.setVisibility(View.INVISIBLE);
                    mTvStatus.setText("待接工单");
                    mTvStatus.setTextColor(Color.parseColor("#66a6ff"));
                    mTvFlag.setVisibility(View.VISIBLE);
                    mTvFlag.setBackgroundColor(Color.parseColor("#66a6ff"));
                    break;
                case "FINISHED":
                    mIvComplete.setVisibility(View.VISIBLE);
                    mTvDate.setTextColor(Color.parseColor("#989DA4"));
                    mTvTitle.setTextColor(Color.parseColor("#989DA4"));
                    mTvStatus.setTextColor(Color.parseColor("#989DA4"));
                    mTvFlag.setVisibility(View.INVISIBLE);
                    break;
                default:
                    break;
            }
        }


    }

    private void setFlagColor(String priorityLevel, TextView mTvStatus) {
        switch (priorityLevel) {
            case "NORMAL":
                mTvStatus.setText("一般");
                mTvStatus.setTextColor(Color.parseColor("#80cb9a"));
                break;
            case "URGENT":
                mTvStatus.setText("紧急");
                mTvStatus.setTextColor(Color.parseColor("#fb5f5f"));
                break;
            case "VERY_URGENT":
                mTvStatus.setText("非常紧急");
                mTvStatus.setTextColor(Color.parseColor("#fb5f5f"));
                break;
            default:
                break;

        }
    }
}

